#include "Skybox.h"

#include <glm\gtc\matrix_transform.hpp>


Skybox::Skybox() :	m_lado(100.0f), m_xpositivo(m_lado, m_lado), m_xnegativo (m_lado, m_lado), m_ypositivo(m_lado, m_lado), m_ynegativo (m_lado, m_lado), m_zpositivo(m_lado, m_lado), m_znegativo (m_lado, m_lado)
{
}


void Skybox::init(const glm::vec3 &DireccionLuz) {
	this->m_xpositivo.init(glm::vec3(0.0f, 0.0f, 100.0f), "TextureShader.vert", "TextureShader.frag");
	this->m_xpositivo.setMaterial(glm::vec3(0.6f, 0.6f, 0.6f), glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(0.0f, 0.0f, 0.0f), 1.0f);
	this->m_xpositivo.setTextura("xpositivo.dds");

	this->m_xnegativo.init(glm::vec3(0.0f, 0.0f, 100.0f), "TextureShader.vert", "TextureShader.frag");
	this->m_xnegativo.setMaterial(glm::vec3(0.6f, 0.6f, 0.6f), glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(0.0f, 0.0f, 0.0f), 1.0f);
	this->m_xnegativo.setTextura("xnegativo.dds");

	this->m_ypositivo.init(glm::vec3(0.0f, 0.0f, 100.0f), "TextureShader.vert", "TextureShader.frag");
	this->m_ypositivo.setMaterial(glm::vec3(0.6f, 0.6f, 0.6f), glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(0.0f, 0.0f, 0.0f), 1.0f);
	this->m_ypositivo.setTextura("ypositivo.dds");

	this->m_ynegativo.init(glm::vec3(0.0f, 0.0f, 100.0f), "TextureShader.vert", "TextureShader.frag");
	this->m_ynegativo.setMaterial(glm::vec3(0.6f, 0.6f, 0.6f), glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(0.0f, 0.0f, 0.0f), 1.0f);
	this->m_ynegativo.setTextura("ynegativo.dds");

	this->m_zpositivo.init(glm::vec3(0.0f, 0.0f, 100.0f), "TextureShader.vert", "TextureShader.frag");
	this->m_zpositivo.setMaterial(glm::vec3(0.6f, 0.6f, 0.6f), glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(0.0f, 0.0f, 0.0f), 1.0f);
	this->m_zpositivo.setTextura("zpositivo.dds");

	this->m_znegativo.init(glm::vec3(0.0f, 0.0f, 100.0f), "TextureShader.vert", "TextureShader.frag");
	this->m_znegativo.setMaterial(glm::vec3(0.6f, 0.6f, 0.6f), glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(0.0f, 0.0f, 0.0f), 1.0f);
	this->m_znegativo.setTextura("znegativo.dds");
}


void Skybox::renderizar(const glm::mat4 &matVista, const glm::mat4 &matProyeccion, const glm::mat4 &matModelo) const {
	float diff=5.0f;

	glm::mat4 matModelFondo = glm::translate(matModelo, glm::vec3(-m_lado/2, -m_lado/2, -m_lado/2 + diff) );
	this->m_xnegativo.renderizar(matVista, matProyeccion, matModelFondo);

	matModelFondo = glm::translate(matModelo, glm::vec3(m_lado/2, -m_lado/2,-m_lado/2 + diff));
	matModelFondo = glm::rotate(matModelFondo, 90.0f, glm::vec3(0.0f, 0.0f, 1.0f));
	this->m_ypositivo.renderizar(matVista, matProyeccion, matModelFondo);

	matModelFondo = glm::translate(matModelo, glm::vec3(-m_lado/2, m_lado/2, -m_lado/2 + diff));
	matModelFondo = glm::rotate(matModelFondo, -90.0f, glm::vec3(0.0f, 0.0f, 1.0f));
	this->m_ynegativo.renderizar(matVista, matProyeccion, matModelFondo);

	matModelFondo = glm::translate(matModelo, glm::vec3(m_lado/2, m_lado/2, -m_lado/2 + diff));
	matModelFondo = glm::rotate(matModelFondo, 180.0f, glm::vec3(0.0f, 0.0f, 1.0f));
	this->m_xpositivo.renderizar(matVista, matProyeccion, matModelFondo);


	matModelFondo = glm::translate(matModelo, glm::vec3(-m_lado/2, -m_lado/2, m_lado/2 + diff));
	matModelFondo = glm::rotate(matModelFondo, 90.0f, glm::vec3(0.0f, 1.0f, 0.0f));
	this->m_zpositivo.renderizar(matVista, matProyeccion, matModelFondo);
}

